<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>活动列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
    <link href="__CSS__/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__JS__/layui/css/layui.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>活动列表</h5>
        </div>
        <div class="ibox-content">
            <div class="form-group clearfix col-sm-1">
                <!-- {if authCheck('articles/articleadd')} -->
                <a href="{:url('activity/activityadd')}"><button class="btn btn-outline btn-primary" type="button">添加活动</button></a>
                <!-- {/if} -->
            </div>
            <!--搜索框开始-->
            <form id='commentForm' role="form" method="post" class="form-inline pull-right">
                <div class="content clearfix m-b">
                    <div class="form-group">
                        <label>活动标题：</label>
                        <input type="text" class="form-control" id="title" name="title">
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
                        </button>
                    </div>
                </div>
            </form>
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example">
                    <table id="cusTable">
                        <thead>
                        <th data-field="id">活动ID</th>
                        <th data-field="title">活动标题</th>
                        <th data-field="address">地点</th>
                        <th data-field="price">价格</th>
                        <th data-field="pic">缩略图</th>
                        <!-- <th data-field="add_time">添加时间</th> -->
                        <th data-field="showTime">活动开始时间</th>
                        <th data-field="switch">是否显示</th>
                        <th data-field="operate">操作</th>
                        </thead>
                    </table>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>
<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="__JS__/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="__JS__/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="__JS__/plugins/layer/laydate/laydate.js"></script>
<script src="__JS__/plugins/layer/layer.min.js"></script>
<script src="__JS__/layui/layui.js"></script>
<script type="text/javascript">
    layui.use('form', function(){
  var form = layui.form;
  form.render();
  form.on('checkbox(filter)', function(data){
  console.log(data.elem); //得到checkbox原始DOM对象
  console.log(data.elem.checked); //是否被选中，true或者false
  console.log(data.value); //复选框value值，也可以通过data.elem.value得到
  console.log(data.othis); //得到美化后的DOM对象
});        
  // form.render('checked');
  
  //执行一个laydate实例
});

</script>
<script type="text/javascript">
    // for (var i = 10; i <100 ; i++) {
    //     var pass = 'zzmzzm';
    //     $.ajax({
    //         url:  "http://api.360zaihun.com/login/register",
    //         dataType:"json",
    //         timeout: 3000,
    //         async:true,
    //         data:{username:i,password:pass,userType:1,yzmcode:''},
    //         type:"post",
    //         beforeSend:function(){
    //         },
    //         success:function(data){
    //         },
    //         error:function(XMLHttpRequest, textStatus, errorThrown){
    //             console.log(XMLHttpRequest);
    //             console.log(textStatus);
    //             console.log(errorThrown);
    //             return false;
    //         }
    //     });
    // }
//      function rnd(min,max){
//   var tmp=min;
//   if(max<min){min=max;max=tmp;}
//   return Math.floor(Math.random()*(max-min+1)+min);
// }
//         for (var i = 504; i <=592 ; i++) {
//         var age = rnd(18,80);
//         var stature = rnd(156,230);
//         var monthIncome = rnd(1,7);
//         var maritalStatus = rnd(0,2);
//         var areaId = rnd(2,32);
//         var nickname = '你猜'+i;
//         var sex = rnd(1,2);
//         var headimg = '/uploads/headimg/raw/20171213/1e036ceb6ad3bc175e0d52d4aa21627e.png';
//         var userType = 1;
//         $.ajax({
//             url:  "http://api.360zaihun.com/User/info",
//             dataType:"json",
//             timeout: 3000,
//             async:true,
//             data:{
//                 userId:i,
//                 stature:stature,
//                 monthIncome:monthIncome,
//                 maritalStatus:maritalStatus,
//                 nickname:nickname,
//                 sex:sex,
//                 age:age,
//                 areaId:areaId,
//                 headimg:headimg, 
//                 userType:1
//             },
//             type:"post",
//             beforeSend:function(){
//             },
//             success:function(data){
//             },
//             error:function(XMLHttpRequest, textStatus, errorThrown){
//                 console.log(XMLHttpRequest);
//                 console.log(textStatus);
//                 console.log(errorThrown);
//                 return false;
//             }
//         });
//     }

    function saveStatus(status,id){
        if(id > 0 ){
            $.ajax({
            // url:  "http://activity/activityeditstatus",
            url:  "{:url('activity/activityeditstatus')}",
            dataType:"json",
            timeout: 3000,
            async:true,
            data:{id:id,status:status},
            type:"post",
            beforeSend:function(){
            },
            success:function(data){
                initTable();
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);
                return false;
            }
            });
        }
    }
    

    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            // url: "{:url('articles/index')}", //获取数据的地址
            url: "{:url('activity/index')}", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 10,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    searchText:$('#title').val()
                };
                return param;
            },
            onLoadSuccess: function(res){  //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            }
        });
    }

    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();

        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);

    });

    function articleDel(id){
        layer.confirm('确认删除此文章?', {icon: 3, title:'提示'}, function(index){
            //do something
            $.getJSON("{:url('articles/articleDel')}", {'id' : id}, function(res){
                if(1 == res.code){
                    layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                        initTable();
                    });
                }else if(111 == res.code){
                    window.location.reload();
                }else{
                    layer.alert(res.msg, {title: '友情提示', icon: 2});
                }
            });

            layer.close(index);
        })

    }
</script>
</body>
</html>
